<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: red;
            float: left;
            margin-right: 10px;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <button onclick="fun()">确定</button>
    <script>
        //1
        var obj = document.querySelector("button");
        obj.onclick = function () {
            var sum = document.querySelectorAll("div");
            for (var i = 0; i < sum.length; i++) {
                sum[i].innerHTML = "这是第" + helper(i) + "个div";
            }
        }
        var helper = function (x) {
            return x + 1;
        }
        //2
        var Car = function () {
            var name = "默认值";
            var color = "red";
            return {
                getName: function () {
                    return name;
                },
                setName: function (na) {
                    name = na;
                },
                getColor: function () {
                    return color;
                },
                setColor: function (col) {
                    color = col;
                }
            }
        }
        var tm = Car();
        console.log(tm.setColor('gray'));
        console.log(tm.getColor());
        console.log(tm.setName('c1901'));
        console.log(tm.getName());

        //3
        // function repeat(fun, nums, times) {
        //     var sum = 0;
        //     var max = setInterval(function () {
        //         sum++;
        //         if (sum == nums) {
        //             clearInterval(max);
        //         } else {
        //             alert(fun);
        //         }
        //     }, times);
        // }
        // repeat("你好", 6, 3000);




        var root = {
            name: 'C盘',
            children: [{
                name: '学习',
                children: [{
                    name: '电子书',
                    children: [
                        {
                            name: '文学',
                            children: [
                                { name: '三体' },
                                { name: '红与黑' }
                            ]
                        }
                    ]
                }
                ]
            }, {
                name: '电影',
                children: [
                    { name: '美国电影' },
                    { name: '日本电影' }
                ]
            }]
        }
    </script>
</body>

</html>